/*cgq 2021 3 26 自定义指令 <div v-draggable>666</div>*/

/**
 * 自动指令
 * 2022 2 15
 * <div v-draggable>666</div>
 */
class instruction {
    __proto__ = "";
    // 拖拽
    draggable = {
        beforeMount(el: any) {
            el.style.cursor = "move";
            el.onmousedown = function (e: any) {
                let disx = e.pageX - el.offsetLeft;
                let disy = e.pageY - el.offsetTop;
                document.onmousemove = function (e) {
                    let x = e.pageX - disx;
                    let y = e.pageY - disy;
                    let maxX =
                        document.body.clientWidth -
                        parseInt(window.getComputedStyle(el).width);
                    let maxY =
                        document.body.clientHeight -
                        parseInt(window.getComputedStyle(el).height);
                    if (x < 0) {
                        x = 0;
                    } else if (x > maxX) {
                        x = maxX;
                    }

                    if (y < 0) {
                        y = 0;
                    } else if (y > maxY) {
                        y = maxY;
                    }
                    el.style.position = "relative";
                    el.style.left = x + "px";
                    el.style.top = y + "px";
                };
                document.onmouseup = function () {
                    document.onmousemove = document.onmouseup = null;
                };
            };
        },
    };

    MU = {
        beforeMount(el, b) {
            let val = b.value
            let fixexs = (val / 100000000).toFixed(2)
            if (fixexs == 'NaN') {
                fixexs = '-'
            }
            el.innerHTML = fixexs + '亿'
        }
    }
    AU = {
        beforeMount(el, b) {
            let val = b.value
            let fixexs = (val / 10000).toFixed(2)
            if (fixexs == 'NaN') {
                fixexs = '-'
            }
            el.innerHTML = fixexs + '万'
        }
    }
    toFixed = {
        beforeMount(el, b) {
            let val = b.value.toFixed(2)
            el.innerHTML = val
        }
    }
    setColour = {
        beforeMount(el, b) {
            let val = b.value
            return el.classList.add(val ? 'red' : 'ls');  
        }
    }
}

export default instruction;

/*  // 指令绑定元素挂载前
beforeMount(el) {},
// 指令绑定元素挂载后
mounted(el, binding) {},
// 指令绑定元素因为数据修改触发修改前
beforeUpdate(el) {},
// 指令绑定元素因为数据修改触发修改后
updated(el) {},
// 指令绑定元素销毁前
beforeUnmount(el) {},
// 指令绑定元素销毁后
unmounted(el) {},*/
